package Tests;

import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import static java.lang.System.*;

public class GraphicsTest {
    public static void main(String[] args) {
        Display frame=new Display();
        Thread loop=new Thread(new GameLoop(frame), "Loop");
        loop.setDaemon(true);
        loop.start();
    }
}


class GameLoop implements Runnable {
    Display frame;

    public GameLoop(Display frame) {
        this.frame=frame;
    }

    @Override
    public void run() {
        while (true) {
            frame.repaint(1000/30);
            try {Thread.sleep(1000/30);} catch (Exception ex) {}
        }
    }
    
}

class Display extends JFrame {
    BufferedImage b;
    Graphics gx;

    public Display() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(640, 480);
        setLocationByPlatform(true);
        setTitle("Graphics Test");
        setVisible(true);
        
    }

    @Override
    public void paint(Graphics g) {
        b=new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
        gx=b.getGraphics();
        gx.clearRect(0, 0, getWidth(), getHeight());
        gx.setColor(Color.red);
        gx.drawRect(50,50,100,100);
        g.drawImage(b, 0, 0, getWidth(), getHeight(), new Color(0.1f, 0.0f, 0.1f),  null);
    }
}
